import React from 'react';
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as Action from "../actions";
import { HashRouter as Router, Route, Link } from 'react-router-dom'


import Header from "../header.js"
import OrderC from "./orderC.js"
class Orderdetails extends React.Component {
    constructor(props) {
        super(props);
        this.state = ({
            countC: 0
        })
        var parm=JSON.parse(sessionStorage.getItem('userOpenid'));
        this.props.actions.showAllorder(`userOpenId=${parm.userOpenId}`);
    }

    addprice(num) {
        this.setState({
            countC: this.state.countC + num
        })
    }
    render() {
        document.title="订单信息";
        var pricec = 0;
        return <Router>
            <div>
                <Header />
                {
                    this.props.orderList.map((item, idx) => {
                        // item.forEach((item1)=>{ pricec+=(item.productQuantity * (item.productPrice * 10000 )) / 10000 })
                        return <OrderC key="idx" orderc={item.productList} createTime={item.createTime} addprice={this.addprice.bind(this)} />
                    })
                }
                <footer>
                    <div className="price">
                        <a>共计</a>
                        <span>￥{this.state.countC}</span>
                    </div>
                    <div className="shopBtn">
                        <Link to="/product">加单</Link>
                    </div>
                </footer>
            </div>
        </Router>
    }
}
export default connect(
    ({ detailsReducer }) => {
        return {
            orderList: detailsReducer.orderList
        }
    },
    (dispatch) => {
        return {
            actions: bindActionCreators(Action, dispatch)
        }
    }
)(Orderdetails)